home *** CD-ROM | disk | FTP | other *** search
/ Family Fun / Family Fun.iso / joke1 / jokes_i / intercal.jok < prev    next >
Internet Message Format  |  1992-01-07  |  54KB

  1. From: ken@aiai.ed.ac.uk (Ken Johnson)
  2. Newsgroups: alt.folklore.computers
  3. Subject: Intercal Manual (was re: Hacker's Dictionary) LONG, 1484 LINES
  4. Date: 26 Apr 90 13:00:21 GMT
  5.  
  6.  
  7. In article <801@barsoom.nhh.no> tih@barsoom.nhh.no (Tom Ivar Helbekkmo)
  8. writes:
  9.  
  10. >I'm all for it!  Let's get hold of some specs and implement the thing!
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.             THE INTERCAL PROGRAMMING LANGUAGE
  18.                 REFERENCE MANUAL
  19.  
  20.  
  21.             Donald R. Woods & James M. Lyon
  22.  
  23.         Copyright Donald R. Woods & James M. Lyon  1973
  24.  
  25.  
  26.  
  27.  
  28.  
  29.                 INTERCAL
  30.  
  31. 1. INTRODUCTION
  32.  
  33. The names you are about to ignore are true. However, the story has been changed
  34. significantly. Any resemblance of the programming language portrayed here
  35. to other programming languages, living or dead, is purely coincidental.
  36.  
  37. 1.1 ORIGIN AND PURPOSE
  38.  
  39. The INTERCAL programming language was designed the morning of May 26, 1972
  40. by Donald R. Woods and James M. Lyon, at Princeton University. Exactly when
  41. in the morning will become apparent in the course of this manual. It was 
  42. inspired by one ambition; to have a compiler language which has nothing at 
  43. all in common with any other major language. By 'major' was meant anything
  44. with which the authors were at all familiar, e.g., FORTRAN, BASIC, COBOL,
  45. ALGOL, SNOBOL, SPITBOL, FOCAL, SOLVE, TEACH, APL, LISP, and PI/I. For the
  46. most part, INTERCAL has remained true to this goal, sharing only the basic
  47. elements such as variables, arrays, and the ability to do I/O, and eschewing 
  48. all conventional operations other than the assignment statement (FORTRAN
  49. "=").
  50.  
  51. 1.2 ACRONYM
  52.  
  53. The full name of the compiler is "Compiler Language With No Pronounceable
  54. Acronym", which is, for obvious reasons, abbreviated "INTERCAL".
  55.  
  56. 1.3 ACKNOWLEDGEMENTS
  57.  
  58. The authors are deeply indebted to Eric M. Van and Daniel J. Warmenhoven,
  59. without whose unwitting assistance this manual would still have been
  60. possible.
  61.  
  62.  
  63.  
  64. 2. FUNDAMENTAL CONCEPTS
  65.  
  66. In this section an attempt is made to describe how and why INTERCAL may be
  67. used; i.e., what it is like and what it is good for.
  68.  
  69. 2.1 SAMPLE PROGRAM
  70.  
  71. Shown below is a relatively simple INTERCAL program which will read in 32-bit
  72. unsigned integers, treat them as signed, 2's-complement numbers, and print out 
  73. their absolute values. The program exits if the absolute value is zero. Note
  74. in particular the inversion routine (statements 6 through 14), which could
  75. be greatly simplified if the subroutine library (see section 5) were used.
  76.  
  77. A more detailed analysis of a program is made in section 6 of this manual.
  78.  
  79.     DO (5) NEXT
  80.     (5) DO FORGET #1
  81.     PLEASE WRITE IN :1
  82.     DO .1 <- 'V":1~'#32768$#0'"$#1'~#3
  83.     DO (1) NEXT
  84.     DO :1 <- "'V":1~'#65535$#0'"$#65535'
  85.         ~'#0$#65535'"$"'V":1~'#0$#65535'"
  86.         $#65535'~'#0$#65535'"
  87.     DO :2 <- #1
  88.     PLEASE DO (4) NEXT
  89.     (4) DO FORGET #1
  90.     DO .1 <- "'V":1~'#65535$#0'"$":2~'#65535
  91.         $#0'"'~'#0$65535'"$"'V":1~'#0
  92.         $#65535'"$":2~'#65535$#0'"'~'#0$#65535'"
  93.     DO (1) NEXT
  94.     DO :2 <- ":2~'#0$#65535'"
  95.         $"'":2~'#65535$#0'"$#0'~'#32767$#1'"
  96.     DO (4) NEXT
  97.     (2) DO RESUME .1
  98.     (1) PLEASE DO (2) NEXT
  99.     PLEASE FORGET #1
  100.     DO READ OUT :1
  101.     PLEASE DO .1 <- 'V"':1~:1'~#1"$#1'~#3
  102.     DO (3) NEXT
  103.     PLEASE DO (5) NEXT
  104.     (3) DO (2) NEXT
  105.     PLEASE GIVE UP
  106.  
  107. 2.2 USES FOR INTERCAL
  108.  
  109. INTERCAL's main advantage over other programming languages is its strict 
  110. simplicity. It has few capabilities, and thus there are few restrictions to
  111. be kept in mind. Since it is an exceedingly easy language to learn, one might
  112. expect it would be a good language for initiating novice programmers. Perhaps
  113. surprising, than, is the fact that it would be more likely to initiate a no-
  114. vice into a search for another line of work. As it turns out, INTERCAL is more
  115. useful (which isn't saying much) as a challlenge to professional programmers.
  116.  Those who doubt this need only refer back to the sample program in section
  117. 2.1. This 23-statement program took somewhere from 15 to 30 minutes to write,
  118. whereas the same objectives can be achieved by single-statement programs in
  119. either SNOBOL;
  120.  
  121.     PLEASE INPUT POS(0) ('-' ! '')
  122.     + (SPAN('0123456789') $ OUTPUT)
  123.     + *NE(OUTPUT) :S(PLEASE)F(END)
  124.  
  125. or APL;
  126.  
  127.     [1] >-0=/?<-?
  128.  
  129. Admittedly, neither of these is likely to appear more intelligible to any-
  130. one unfamiliar with the languages involved, but they took roughly 60 seconds
  131.  and 15 seconds, respectively, to write. Such is the overwhelming power of 
  132. INTERCAL!
  133.  
  134. The other major importance of INTERCAL lies in its seemingly inexhaustible
  135. capacity for amazing one's fellow programmers, confounding programming shop
  136. managers, winning friends, and influencing people. It is a well-known and
  137. oft-demonstrated fact that a person whose work is incomprehensible is held
  138. in high esteem. For example, if one were to state that the simplest way to
  139. store a value of 65535 in a 32-bit INTERCAL variable is:
  140.  
  141.     DO :1 <- #0?#256
  142.  
  143. any sensible programmer would say that that was absurd. Since this is in-
  144. deed the simplest method, the programmer would be made to look foolish in 
  145. front of his boss, who would of course happened to turn up, as bosses are
  146. wont to do. The effect would be no less devastating for the programmer hav-
  147. ing been correct.
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155. 3. DESCRIPTION
  156.  
  157. The examples of INTERCAL programming which have appeared in the preceeding
  158. sections of this manual have probably seemed highly esoteric to the reader
  159. unfamiliar with the language. With the aim of making them more so, we pre-
  160. sent here a description of INTERCAL.
  161.  
  162.  
  163. 3.1 VARIABLES
  164.  
  165. INTERCAL allows only 2 different types of variables, the 16-bit integer, and
  166. the 32-bit interger. These are represented by a spot (.) or two-spot (:),
  167. respectively, followed by any number between 1 and 65535, inclusive. These
  168. variables may contain only non-negative numbers; thus they have the respec-
  169. tive ranges of values: 0 to 65535 and 0 to 4294967295. Note: .123 and :123
  170. are two distinct variables. On the other hand, .1 and .0001 are identical.
  171. Furthermore, the latter mau NOT be written as 1E-3.
  172.  
  173. 3.2 CONSTANTS
  174.  
  175. Constants are 16-bit values only and may range from 0 to 65535. Thay are
  176. prefixed by a mesh (#). Caution! Under no circumstances confuse the mesh
  177. with the interleave operator, except under confusing circumstances!
  178.  
  179. 3.3 ARRAYS
  180.  
  181. Arrays are reprsented by a tail (,) for 16-bit values, or a hybrid (;) for
  182. 32-bit values, followed by a number between 1 and 65535, inclusive. The
  183.  number is suffixed by the word SUB, followed by the subscripts, separated
  184.  optionally by spaces. Subscripts may be any expressions, including those 
  185. involving subscripted variables. This occasionally leads to ambiguous con-
  186. structions, which are resolved as discussed in section 3.4.3 Definition of
  187. array dimensions will be discussed later in greater detail, sice discussing
  188. it in less detail would be difficult. As before, ,123 and ;123 are distinct.
  189. In summary, .123, :123, #123, ,123, and :123 are all distinct.
  190.  
  191. 3.4 OPERATORS
  192.  
  193. INTERCAL recognizes 5 operators--2 binary and 3 unary. Please be kind to 
  194. our operators: they may not be very intelligent, but they're all we've got.
  195. In a sense, all 5 operators are binary, as they are all bit-oriented, but
  196. it is not our purpose here to quibble about bits of trivia.
  197.  
  198.  
  199.  
  200. ******* proofread versus the paper copy only this far !!!! ************
  201.  
  202.  
  203.  
  204.  
  205. 3.4.1 BINARY OPERATORS
  206.  
  207. The binary operators are INTERLEAVE (also called MINGLE) and SELECT, which
  208. are represented by a change (c) and a sqiggle [sic] (~), respectively.
  209.  
  210. The interleave operator takes two 16-bit values and produces a 32-bit result
  211. by alternating the bits of the operands. Thus, #65535c#0 has the 32-bit
  212. binary form 101010....10 or 2863311530 decimal, while #0c#65535 = 
  213. 0101....01 binary = 1431655765 decimal, and #255c#255 is equivalent to
  214. #65535.
  215.  
  216. The select operator takes from the first operand whichever bits correspond
  217. to 1's in the second operand, and packs these bits as the right in the result.
  218. Both operands are automatically padded on the left with zeros to 32 bits
  219. before the selction takes place, so the variable types are unresrticted.
  220. If more than 16 bits are selected, the result is a 32-bit value, otherrwise
  221. it is a 16-bit value. For example, #179~#201 (binary value 10110011~11001001)
  222. selects from the first argument the 8th, 7th, 4th, and 1st from last bits,
  223. namely, 1001, which = 9. But #201~#179 selects from binary 11001001 the 8th,
  224. 6th, 5th, 2nd, and 1st from last bits, giving 10001 = 17. #179~#179 has the
  225. value 31, while #201~#201 has the value 15.
  226.  
  227. Perhaps a simpler way of understanding the operation of the select operator
  228. would be to examine the logic diagram on the following page (Figure 1), which
  229. performs the select operstion upon two 8-bit values, A and B. The gates used
  230. are Warmenhovian logic gates, which means the outputs have four possible
  231. values: low, high, undefined (value of an uninitialized flip-flop), and
  232. oscillating (output of a NOR gate with one input low and the other input
  233. connected to the output). These values are represented symbolocally by '0',
  234. '1', '2', and 'F'. Note in particular that, while NOT-0 is 1 and NOT-2 
  235. is 0 as in two-valued logic, NOT-? is ? and NOT-F is F. The functions 
  236. of the various gates are listed on Table 1.
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244. 3.4.2 UNARY OPERATORS
  245.  
  246. The unary operators a & (loghical AND), V (logical OP), and V (logical
  247. XOR). This last character is obtained by overpunching a worm (-) on a V (V).
  248. The operator is inserted between the spot, two-spot, mesh, or what-have-you,
  249. and the integer, thus: .&123, #V123. Multipe unary operators may not be
  250. concatenated, thus the form #V&123 is invalid. This will be covered later 
  251. when precedence is discussed. These operators perform their respective
  252. logical operations on all pairs of adjacent bits, the result from the first
  253. and last bits going into the first bit of the result. The effect is that of
  254. rotating the operand one place to the right and ANDing, ORing, or XORing
  255. with its initial value. Thus, #&77 (binary = 1001101) is binary 000000000000
  256. 0100 = 4, #V77 is binary 1000000001101111 = 32879, and #V77 is binary
  257. 1000000001101011 = 32875.
  258.  
  259. 3.4.3 PRECEDENCE
  260.  
  261. Precedence of operators is as follows:
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.                                                             [1]
  274. (The remainder of this page intentionally left blank)
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288. _________________
  289. 1) Keep in mind that the aim in designing INTERCAL was to have no 
  290.    precedents.
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298. This precedence (or lack therreof) may be overruled by grouping expressions
  299. between pairs of sparks (') or rabbit-ears ("). Thus '#165c#203'~#358 
  300. binary value '10100101c11001011'~101100110) has the value 15, but
  301. #165c'#203~#358' has the value 34815, and #165c#203~#358 is invalid
  302. syntax and is completely valueless (except perhaps as an educational tool
  303. to the programmer). A unary operator is applied to a sparked or rabbit-eared
  304. expression by inserting the operator immediately following the opening spark
  305. or ears. Thus, the invalid expression #V&123, which was described earlier,
  306. could be coded a 'V#&123' or 'V"{"'. Note: In the interests of 
  307. simplifying the sometimes overly-complex form of expressions, INTERCAL allows
  308. a spark-spot combination ('.) to be replaced with a wow (!). Thus '.1~.2'
  309. is equivalent to !1~.2', and 'V.1c.2' is equivalent to "V!1c.2'".
  310.  
  311. Combining a rabbit-ears with a spot to form a rabbit (V) is not permitted,
  312. although the programmer is free to use it should he find an EBCDIC reader
  313. which will properly translate a 12-3-7-8 punch.
  314.  
  315. Sparks and/or rabbit-ears must also be used to distinguish among such other-
  316. wise ambiguous subscripted and multipy-subscripted expressions as:
  317.  
  318.     ,1 SUB #1 ~ #2
  319.     ,1 SUB ,2 SUB #1 #2 #3
  320.     ,1 SUB " ,2 SUB " ,3 SUB #1 " #2 " " #3 "
  321.  
  322. The third case may be isolated into either of its possible interpretations
  323. by simply changing some pairs of rabbit-ears to sparks, instead of adding
  324. more ears (which would only confuse the issue further). Ambiguous cases are
  325. defined as those for which the compiler being used finds a legitimate inter-
  326. pretation which is different from that which the user had in mind. See also
  327. section 8.1.
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. 4. STATEMENTS
  335.  
  336. In this section is described the format of INTERCAL statements.
  337.  
  338. 4.1 GENERAL FORMAT
  339.  
  340. Statements may be entered in 'free format'. That is, more than one statement
  341. may occur on a single card, and a statement may begin on one card and end
  342. on a later one. Note that if this is done, all intervening cards and portions
  343. thereof must be part of the same statement. That this restriction is necessary
  344. is immediately apparent from the following example of what, might occur if
  345. statements could be interlaced.
  346.  
  347.     DO .1 <- ".1c'&:51~"#V1c!12~;&75SUB"V'V.1~
  348.     DO .2 <- '"!1c"&';V79SUB",&7SUB:173"'~!V9c
  349.     .2'c,&1SUB:5~#33578"'"'"~'#65535c"V'V#&85'"'
  350.     #8196'"'~.1"c.2'~'#&5c"'#1279c#4351'~#65535"'
  351.  
  352. The above statements are obviously meaningless. (For that matter, so are
  353. the statements
  354.  
  355.     DO .1 <- ".1c"&:51~"#V1C!12~;&75SUB"V'V.1~
  356.     .2'C,&1SUB:5~/333578"'"'"~#65535c"V'V#&85'"'
  357.     DO .2 <- '"!1c"&';V79SUB",&7SUB:173"'~!V9c
  358.     #8196'"'~.1"c.2'~'#&5c"'#1279c!4351'~#65535"'
  359.  
  360. but this is not of interest here.)
  361.  
  362. Spaces may be used freely to enhance program legibility (or at least reduce
  363. program illegibility), with the restriction that no word of a statement ident
  364. -ifier (see section 4.3) may contain any spaces.
  365.  
  366. 4.2 LABELS
  367.  
  368. A statement may begin with a LOGICAL LINE LABEL enclosed in wax-wane pairs
  369. (()). A statement may not have more than one label, although it is possible
  370. to omit the label entirely. A line label is any integer from 1 to 65535,
  371. which must be unique within each program. The user is cautioned, however,
  372. that many line labels between 1000 and 1999 are used in the INTERCAL System
  373. Library functions.
  374.  
  375. 4.3 IDENTIFIERS AND QUALIFIERS
  376.  
  377. After the line label (if any), must follow one of the following statement 
  378. identifiers: DO, PLEASE, or PLEASE DO. These may be used interchangeably to
  379. improve the aesthetics of the program. The identifier is then followed by
  380. either, neither, or both of the following optional parameters (qualifiers):
  381. (1) either of the character strings NOT or N'T, which causes the statement
  382. to be automatically abstained from (see section 4.4.9) when execution begins,
  383. and (2) a number between 0 and 100, preceded by a double-oh-seven (%), which
  384. causes the statement to have only the specified percent chance of being exe-
  385. cuted each time it is encountered in the course of execution.
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393. 4.4 STATEMENTS
  394.  
  395. Following the qualifiers (or, if none are used, the identifier) must occur
  396. one of the 13 valid operations. (Exception: see section 4.5.) These are 
  397. described individually in sections 4.4.1 through 4.4.13.
  398.  
  399. 4.4.1 CALCULATE
  400.  
  401. The INTERCAL equivalent of the half-mesh (=) in FORTRAN, BASIC, PL/I, and
  402. others, is represented by an angle (<) followed by a worm (-). This combi-
  403. nation is read 'gets'. 32-bit variables may be assigned 16-bit values, which 
  404. are padded on the left with 16 zero bits. 16-bit variables may be assigned
  405. 32-bit values only if the value is less than 65535. Thus, to invert the least
  406. significant bit of the first element of 16-bit 2-dimensional array number 1,
  407. one could  write:
  408.  
  409.     ,1SUB#1#1 <- 'V,1SUB#1#1c#1'~'#0c#65535'
  410.  
  411. Similarly to SNOBOL and SPITBOL, INTERCAL uses the angle-worm to define the
  412. dimensions of arrays. An example will probably best describe the format. 
  413. To define 32-bit array number 7 as 3-dimensional, the first dimension being
  414. seven, the second being the current value of 16-bit variable number seven,
  415. and the third being the current value of the seventh element of 16-bit array
  416. number seven (which is one-dimensional) mingled with the last three bits of
  417. 32-bit variable number seven, one would write (just before they came to take
  418. him away):
  419.  
  420.     ;7 <- #7 BY .7 BY ",7SUB#7/'c':7~#7'
  421.  
  422. This is, of course, different from the statement:
  423.  
  424.     ;7 <- #7 BY .7 BY ,7SUB"#7c':7~#7'"
  425.  
  426. INTERCAL also permits the redefining of array dimensioning, which is done 
  427. the same way as is the initial dimensioning. Allvalues of items in an array
  428. are lost upon redimensioning, unless they have been STASHed (see section
  429. 4.4.5), in which case restoring them also restores the old dimensions.
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437. 4.4.2 NEXT
  438.  
  439. The NEXT statement is used both for subroutine calls and for unconditional
  440. transfers. This statement takes the form:
  441.  
  442.     DO (label) NEXT
  443.  
  444. (or, of course,
  445.  
  446.     PLEASE DO (label) NEXT
  447.  
  448. etc.), where (label) represents any logical line label which appears in the
  449. program. The effect of such a  statement is to transfer control to the state-
  450. mant specified, and to store in a push down list (which is initially empty)
  451. the location from which the transfer takes place. Items may be removed from
  452. this list and may be discarded or used to return to the statement immediately
  453. following the NEXT statement. These operations are described in sections 
  454. 4.4.3 and 4.4.4 respectively. The programmer is generally advised to discard
  455. any stack entries which he does not intend to utilize, since the stack has
  456. a maximum depth of 79 enteies. A program's attempting to initiate an 80th
  457. level of NEXTing will result on the fatal error message, "PROGRAM HAS DIS-
  458. APPEARED INTO THE BLACK LAGOON."
  459.  
  460. 4.4.3 FORGET
  461.  
  462. The staement PLEASE FORGET exp, where exp represents any expression (except
  463. colloquial and facial expressions), causes the expression to be evaluated,
  464. and the specified number of entries to be removed from the NEXTing stack
  465. and discarded. An attempt to FORGET more levels of NEXTing than are currently
  466.  stacked will cause the stack to be emptied, and no error condition is indi-
  467. cated. This is because the condition is not considered to be an error. As
  468. described in section 4.4.2, it is good programming practice to execute a DO
  469. FORGET #1 after using a NEXT statement as an unconditional transfer, so 
  470. that the stack does not get cluttered up with unused entries:
  471.  
  472.     DO (123) NEXT
  473.     .
  474.     .
  475.   (123) DO FORGET #1
  476.  
  477. 4.4.4 RESUME
  478.  
  479. The statement PLEASE RESUME exp has the same effect as FORGET, except that
  480. program control os returned to the statement immediately following the NEXT
  481. statement which stored in the stack the last entry to be removed. Note that
  482. a rough equivalent of the FORTRAN computed GO TO and BASIC ON exp GO TO is
  483. performed by a sequence of the form:
  484.  
  485.     DO (1) EXT
  486.     .
  487.     .
  488.     (1) DO (2) NEXT
  489.     PLEASE FORGET #1
  490.     .
  491.     .
  492.     (2) DO RESUME .1
  493.  
  494. Unlike the FORGET statement, an attempt to RESUME more levels of NEXTing than
  495. been stacked will cause program termination. Se also section 4.4.11.
  496.  
  497.  
  498. 4.4.5 STASH
  499.  
  500. Since subroutines are nit explicitly implemented in INTERCAL, the NEXT and
  501. RESUME  statements must be used to execute common routines. However, as
  502. these routines might use tje sa,e variabless as the ,ain program, it is
  503. necessary for them to save the values of any variables whose values they
  504. alter, and later restore them. This process is simplified by the STASH state-
  505. ment, which has the form DO STASH list, where list represents a string of
  506. one or more variable or array names, seperated by intersections (+). Thus
  507.  
  508.     PLEASE STASH .123+:123+,123
  509.  
  510. stashes the values of two variables and one entire array. The values are
  511. left intact, and copies thereof are saved for later retrieval by (what else?)
  512. the RETRIEVE statement (see section 4.4.6). It is not possible to STASH
  513. single array items.
  514.  
  515. 4.4.6 RETRIEVE
  516.  
  517. PLEASE RETRIEVE list restores the previously STASHed values of the variables
  518. and arrays named in the list. If a value has been stashed more than once,
  519. teh most recently STASHed values are RETRIEVEd, and a second RETRIEVE will
  520. restore the second most recent values STASHed. Attempting to RETRIEVE a
  521. value which has not been STASHed will result in the error message, "THROW
  522. STICK BEFORE RETIEVING."
  523.  
  524. 4.4.7 IGNORE
  525.  
  526. The statement DO IGNORE list causes all subsequent statements to have no 
  527. effect upon variables and/or arrays named in the list. Thus, for example, 
  528. after the sequence
  529.  
  530.     DO .1 <- #1
  531.     PLEASE IGNORE .1
  532.     DO .1 <- #0
  533.  
  534. 16-bit variable number 1 would have the value 1, not 0. Inputting (see sec-
  535. tion 4.4.12) into an IGNOREd variable also has no effect. The condition is
  536.  annulled via the REMEMBER statement (see section 4.4.8). Note that, when
  537. a variable is being IGNOREd, its value, though immutable, is still avail-
  538. able for use in expressions and the like.
  539.  
  540. 4.4.8 REMEMBER
  541.  
  542. PLEASE REMEMBER list terminates the effect of the IGNORE statement for all
  543. variables and/or arrays named in the list. It does not matter if a variable
  544. has been IGNOREd more than once, nor is it an error of the variable has not
  545. been IGNOREd at all.
  546.  
  547. 4.4.9 ABSTAIN
  548.  
  549. INTERCAL contains no simple equivalent to an IF statement or computed GO TO,
  550. making it difficult to combine similar sections of code into a single rou-
  551. tine which occasionally skips around certain statements. The IGNORE state-
  552. ment (see section 4.4.7) is helpful in some cases, but a more viable method
  553. is often required. Inkeeping with the goal of INTERCAL having nothing in
  554. common with any other language, this is made possible via the ABSTAIN state-
  555. ment.
  556.  
  557. This statement takes on one of two forms. It may not take on both at any one
  558. time. DO ABSTAIN FROM (label) causes the statement whose logical line label
  559. is (label) to be abstained form. PLEASE ABSTAIN FROM gerund list causes all
  560. statements of the specified type(s) to be abstained from, as in
  561.  
  562.     PLEASE ABSTAIN FROM STASHING
  563.     PLEASE ABSTAIN FROM IGNORING + FORGETTING
  564.     PLEASE ABSTAIN FROM NEXTING
  565.      or PLEASE ABSTAIN FROM CALCULATING
  566.  
  567. Statements may also be automatically abstained from at the start of execu-
  568. tion via the NOT nr N'T parameter (see section 4.3).
  569.  
  570.  
  571. If, in the course of execution, a statement is encountered which is being
  572. abstained from, it is ignored and control passes to the next statement in
  573. the program (unless it, too, is being abstained from).
  574.  
  575. The statement DO ABSTAIN FROM ABSTAINING is perfectly valid, as is DO ABSTAIN
  576. FROM REINSTSTING (altough this latter is not usually recommended.) However,
  577. the statement DO ABSTAIN FROM GIVING UP is not accepted, even though DON'T
  578. GIVE UP is.
  579.  
  580. 4.4.10 REINSTATE
  581.  
  582. The REINSTATE statement, like the ABSTAIN, takes as an argument either a 
  583. line label or a gerund list. No other form of argument is permitted. For
  584. example, the following is an invalid argument:
  585.  
  586.     Given: x=/0, y=/o,  Prove: x+y=0
  587.     Since x=/0, then x+1=/1, x+a=/a, x+y=/y.
  588.     Thus x+y =/ anything but 0.
  589.     Since x+y cannot equal anything but 0, x+y=0.
  590.  
  591.                                     Q.E.D.
  592.  
  593. REINSTATEment nullifies the effects of an abstention. Either form of REIN-
  594. STATEment can be used to "free" a statement, regardless of whether the state-
  595. ment was abstained from by gerund list, line label, or NOT. Thus, PPLEASE
  596. REINSTATE REINSTATING is not necessarily an irrelavant statement, since it
  597. might free a DON'T REINSTATE command or a REINSTATE the line label of which
  598.  was abstained from. However, DO REINSTATE GIVING UP is invalid, and attempt-
  599. ing to REINSTATE a GIVE UP statement by line label will have no effect. Note
  600. that this insures that DON'T GIVE UP will always be a "do-nothing" statement.
  601.  
  602. 4.4.11 GIVE UP
  603.  
  604. PLEASE GIVE UP is used to exit from a program. It has the effect of a PLEASE
  605. RESUME #80. DON'T GIVE UP, as noted in section 4.4.10, is effectively a null
  606. statement.
  607.  
  608. 4.4.12 Input
  609.  
  610. Input is accomplished with the statement DO WRITE IN list, where list repre-
  611. sents a string of variables and/or elements or arrays, separated by inter-
  612. sections. Numbers are represented on cards, each number on a separate card,
  613. by spelling out each digit (in English) and separating the digits with one
  614. or more spaces. A zero (0) may be spelled as either ZERO or OH. Thus the
  615. range of (32-bit) input values permissible extends from ZERO (or OH) through
  616. FOUR TWO NINE FOUR NINE SIX SEVEN TWO NINE FIVE.
  617.  
  618. Attempting To write in a value greater than or equal to SIX FIVE FIVE three
  619. six for a 16-bit variable will result in the error message, "DON'T BYTE OFF
  620. MORE THAN YOOU CAN CHEW."
  621.  
  622. 4.4.13 Output
  623.  
  624. Values may be output to the printer, one value per line, via the statement
  625. DO READ OUT list, where the list contains variables, array elements, and/or
  626. constants. Output is in the form of "extended"_Roman numerals (also called
  627. "butchered Roman numerals), with an overline ( ) indicating the value below
  628. is "times 1000", and lower-case letters indicating "times 1000000". Zero
  629. is indicated by an overline with no character underneath. Thus, the range 
  630. of (32-bit) output values possible is from   through ivccxcivCMLXVIICCXCV.
  631. Note: For values whose residues modulo 1000000 are less than 4000, M is
  632. used to represent 1000; for values whose residues are 400 or greater, I is
  633. used. Thus #3999 would read out as MMMIM while #4000 would read out as IV> 
  634. Similar rules apply to the use of M and i for 1000000, and to that of m and
  635. i for 1000000000.
  636.  
  637.  
  638.  
  639.  
  640.  
  641.  
  642.  
  643.  
  644. 4.4.4 RESUME
  645.  
  646. The statement PLEASE RESUME exp has the same effect as FORGET, except that
  647. program control os returned to the statement immediately following the NEXT
  648. statement which stored in the stack the last entry to be removed. Note that
  649. a rough equivalent of the FORTRAN computed GO TO and BASIC ON exp GO TO is
  650. performed by a sequence of the form:
  651.  
  652.     DO (1) EXT
  653.     .
  654.     .
  655.     (1) DO (2) NEXT
  656.     PLEASE FORGET #1
  657.     .
  658.     .
  659.     (2) DO RESUME .1
  660.  
  661. Unlike the FORGET statement, an attempt to RESUME more levels of NEXTing than
  662. been stacked will cause program termination. Se also section 4.4.11.
  663.  
  664.  
  665. 4.4.5 STASH
  666.  
  667. Since subroutines are nit explicitly implemented in INTERCAL, the NEXT and
  668. RESUME  statements must be used to execute common routines. However, as
  669. these routines might use tje sa,e variabless as the ,ain program, it is
  670. necessary for them to save the values of any variables whose values they
  671. alter, and later restore them. This process is simplified by the STASH state-
  672. ment, which has the form DO STASH list, where list represents a string of
  673. one or more variable or array names, seperated by intersections (+). Thus
  674.  
  675.     PLEASE STASH .123+:123+,123
  676.  
  677. stashes the values of two variables and one entire array. The values are
  678. left intact, and copies thereof are saved for later retrieval by (what else?)
  679. the RETRIEVE statement (see section 4.4.6). It is not possible to STASH
  680. single array items.
  681.  
  682. 4.4.6 RETRIEVE
  683.  
  684. PLEASE RETRIEVE list restores the previously STASHed values of the variables
  685. and arrays named in the list. If a value has been stashed more than once,
  686. teh most recently STASHed values are RETRIEVEd, and a second RETRIEVE will
  687. restore the second most recent values STASHed. Attempting to RETRIEVE a
  688. value which has not been STASHed will result in the error message, "THROW
  689. STICK BEFORE RETIEVING."
  690.  
  691.  
  692.  
  693.  
  694.  
  695.  
  696.  
  697.  
  698.  
  699. 4.4.7 IGNORE
  700.  
  701. The statement DO IGNORE list causes all subsequent statements to have no 
  702. effect upon variables and/or arrays named in the list. Thus, for example, 
  703. after the sequence
  704.  
  705.     DO .1 <- #1
  706.     PLEASE IGNORE .1
  707.     DO .1 <- #0
  708.  
  709. 16-bit variable number 1 would have the value 1, not 0. Inputting (see sec-
  710. tion 4.4.12) into an IGNOREd variable also has no effect. The condition is
  711.  annulled via the REMEMBER statement (see section 4.4.8). Note that, when
  712. a variable is being IGNOREd, its value, though immutable, is still avail-
  713. able for use in expressions and the like.
  714.  
  715. 4.4.8 REMEMBER
  716.  
  717. PLEASE REMEMBER list terminates the effect of the IGNORE statement for all
  718. variables and/or arrays named in the list. It does not matter if a variable
  719. has been IGNOREd more than once, nor is it an error of the variable has not
  720. been IGNOREd at all.
  721.  
  722. 4.4.9 ABSTAIN
  723.  
  724. INTERCAL contains no simple equivalent to an IF statement or computed GO TO,
  725. making it difficult to combine similar sections of code into a single rou-
  726. tine which occasionally skips around certain statements. The IGNORE state-
  727. ment (see section 4.4.7) is helpful in some cases, but a more viable method
  728. is often required. Inkeeping with the goal of INTERCAL having nothing in
  729. common with any other language, this is made possible via the ABSTAIN state-
  730. ment.
  731.  
  732. This statement takes on one of two forms. It may not take on both at any one
  733. time. DO ABSTAIN FROM (label) causes the statement whose logical line label
  734. is (label) to be abstained form. PLEASE ABSTAIN FROM gerund list causes all
  735. statements of the specified type(s) to be abstained from, as in
  736.  
  737.     PLEASE ABSTAIN FROM STASHING
  738.     PLEASE ABSTAIN FROM IGNORING + FORGETTING
  739.     PLEASE ABSTAIN FROM NEXTING
  740.      or PLEASE ABSTAIN FROM CALCULATING
  741.  
  742. Statements may also be automatically abstained from at the start of execu-
  743. tion via the NOT nr N'T parameter (see section 4.3).
  744.  
  745.  
  746. If, in the course of execution, a statement is encountered which is being
  747. abstained from, it is ignored and control passes to the next statement in
  748. the program (unless it, too, is being abstained from).
  749.  
  750. The statement DO ABSTAIN FROM ABSTAINING is perfectly valid, as is DO ABSTAIN
  751. FROM REINSTSTING (altough this latter is not usually recommended.) However,
  752. the statement DO ABSTAIN FROM GIVING UP is not accepted, even though DON'T
  753. GIVE UP is.
  754.  
  755.  
  756.  
  757.  
  758.  
  759. 4.4.10 REINSTATE
  760.  
  761. The REINSTATE statement, like the ABSTAIN, takes as an argument either a 
  762. line label or a gerund list. No other form of argument is permitted. For
  763. example, the following is an invalid argument:
  764.  
  765.     Given: x=/0, y=/o,  Prove: x+y=0
  766.     Since x=/0, then x+1=/1, x+a=/a, x+y=/y.
  767.     Thus x+y =/ anything but 0.
  768.     Since x+y cannot equal anything but 0, x+y=0.
  769.  
  770.                                     Q.E.D.
  771.  
  772. REINSTATEment nullifies the effects of an abstention. Either form of REIN-
  773. STATEment can be used to "free" a statement, regardless of whether the state-
  774. ment was abstained from by gerund list, line label, or NOT. Thus, PPLEASE
  775. REINSTATE REINSTATING is not necessarily an irrelavant statement, since it
  776. might free a DON'T REINSTATE command or a REINSTATE the line label of which
  777.  was abstained from. However, DO REINSTATE GIVING UP is invalid, and attempt-
  778. ing to REINSTATE a GIVE UP statement by line label will have no effect. Note
  779. that this insures that DON'T GIVE UP will always be a "do-nothing" statement.
  780.  
  781. 4.4.11 GIVE UP
  782.  
  783. PLEASE GIVE UP is used to exit from a program. It has the effect of a PLEASE
  784. RESUME #80. DON'T GIVE UP, as noted in section 4.4.10, is effectively a null
  785. statement.
  786.  
  787. 4.4.12 Input
  788.  
  789. Input is accomplished with the statement DO WRITE IN list, where list repre-
  790. sents a string of variables and/or elements or arrays, separated by inter-
  791. sections. Numbers are represented on cards, each number on a separate card,
  792. by spelling out each digit (in English) and separating the digits with one
  793. or more spaces. A zero (0) may be spelled as either ZERO or OH. Thus the
  794. range of (32-bit) input values permissible extends from ZERO (or OH) through
  795. FOUR TWO NINE FOUR NINE SIX SEVEN TWO NINE FIVE.
  796.  
  797. Attempting To write in a value greater than or equal to SIX FIVE FIVE three
  798. six for a 16-bit variable will result in the error message, "DON'T BYTE OFF
  799. MORE THAN YOOU CAN CHEW."
  800.  
  801. 4.4.13 Output
  802.  
  803. Values may be output to the printer, one value per line, via the statement
  804. DO READ OUT list, where the list contains variables, array elements, and/or
  805. constants. Output is in the form of "extended"_Roman numerals (also called
  806. "butchered Roman numerals), with an overline ( ) indicating the value below
  807. is "times 1000", and lower-case letters indicating "times 1000000". Zero
  808. is indicated by an overline with no character underneath. Thus, the range 
  809. of (32-bit) output values possible is from   through ivccxcivCMLXVIICCXCV.
  810. Note: For values whose residues modulo 1000000 are less than 4000, M is
  811. used to represent 1000; for values whose residues are 400 or greater, I is
  812. used. Thus #3999 would read out as MMMIM while #4000 would read out as IV> 
  813. Similar rules apply to the use of M and i for 1000000, and to that of m and
  814. i for 1000000000.
  815.  
  816.  
  817.  
  818.  
  819.  
  820.  
  821.  
  822. 4.5 Comments
  823.  
  824. Unrecognizable statements, as noted in section 7, are flagged with a splat
  825. (*) during compilation, and are not considered fatal errors unless they
  826. areencountered during execution, at which time the atatement (as input at 
  827. compilation time) is printed and execution is terminated. This allows for 
  828. an interesting (and, by necessity, unique) means of including comments in 
  829. an INTERCAL listing. For example, the statement:
  830.  
  831. *    PLEASE NOTE THAT THIS LINE HAS NO EFFECT
  832.  
  833. will be ignored during execution due to the inclusion of the NOT qualifier.
  834. User-supplied error messages are also easy to implement:
  835.  
  836. *    DO SOMETHING ABOUT OVERFLOW IN ;3
  837.  
  838. as are certain simple conditional errors:
  839.  
  840. * (123)    DON'T YOU REALIZE THIS STATEMENT SHOULD ONLY BE ENCOUNTERED
  841.         ONCE?
  842.     PLEASE REINSTATE (123)
  843.  
  844. This pair of statements will cause an error exit the second time they are
  845. encountered. Caution!! The appearance of a statement identifier in an in-
  846. tended comment will be taken as the beginning of a new statement. Thus, the
  847. first example on the prceding page could not have been:
  848.  
  849. *     PLEASE NOTE THAT THIS LINE DOES NOTHING
  850.  
  851. The third example, however, is valid, despite the appearance of two cases 
  852. of D-space-0, since INTERCAL does not ignore extraneous spaces in statement
  853. identifiers.
  854.  
  855.  
  856.  
  857.  
  858.  
  859.  
  860. 5. SUBROUTINE LIBRARY
  861.  
  862. INTERCAL provisws severa; bio;t-in subroutines to which control can be trans-
  863. ferred to perform various operations. These operations include many useful
  864.  functions which are not easily representable in INTERCAL, such as addition,
  865. subtraction, etc.
  866.  
  867. 5.1 Usage
  868.  
  869. In general, the operands are .1, .2, etc., or :1, :2, etc., and the result(s)
  870. are stored in what would have been the next operand(s). For instance, one
  871. routine adds .1 to .2 and store the sum in .3, with .4 being used to indicate
  872. overflow. All variables not used for results are left unchanged.
  873.  
  874. 5.2 Available Functions
  875.  
  876. At the time of this writing, only the most fundamental operations are offered
  877. in the library, as a more complete selection would require prohibitive time
  878. and coree to implement. These function, along with their corresponding entry
  879. points (entered via DO (entry) NEXT) are listed below.
  880.  
  881.  (1000)    .3 <- .1 plus .2, erroe exit on overflow
  882.  (1009)    .3 <- .1 plus .2
  883.     .4 <- #1 if no overflow, else .4 <- #2
  884.  (1010)    .3 <- .1 minus .2, no action on overflow
  885.  (1020)    .1 <- .1 plus #1, no action on overflow
  886.  (1030)    .3 <- .1 times .2, error exit on overflow
  887.  (1039)    .3 <- .1 times .2
  888.     .4 <- #1 if no overflow, else .4 <- #2
  889.  (1040)    .3 <- .1 divided by .2
  890.     .3 <- #0 if .2 is #0
  891.  (1050) .2 <- :1 divided by .1, error exit on overflow
  892.     .2 <- #0 if .1 is #0
  893.  
  894.  (1500) :3 <- :1 plus :2, error exit on overflow
  895.  (1509) :3 <- :1 plus :2
  896.     :4 <- #1 if no overflow, else :4 <- #2
  897.  (1510) :3 <- :1 minus :2, no action on overflow
  898.  (1520) :1 <- .1 concatenated with .2
  899.  (1525) This subroutine is intended solely for internal
  900.     use within the subroutine library and is therefore
  901.     not described here. Its effect is to shift .3 logic-
  902.     ally 8 bits to the left.
  903.  (1530) :1 <- .1 times .2
  904.  (1540)    :3 <- :1 times :2, error exit on overflow
  905.  (1549)    :3 <- :1 times :2
  906.     :4 <- #1 if no overflow, else :4 <- #2
  907.  (1550)    :3 <- :1 divided by :2
  908.     :3 <- #0 if :2 is #0
  909.  
  910.  (1900)    .1 <- uniform random no. from #1 to #65535
  911.  (1910) .2 <- normal random no. from #0 to .1, with
  912.           standard deviation .1 divided by #12
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.  
  920. 6. PROGRAMMING HINTS
  921.  
  922. For the user looking to become more familiar with the INTERCAL language, we
  923. present in this section an analysis of a complex program, as well as some
  924. suggested projects for the ambitious programmer.
  925.  
  926. Considering the effort involved in writing an INTERCAL program, it was 
  927. decided in putting together this manual to use an already existing program 
  928. for instructive analysis. Since there was only one such program available,
  929. we have proceded to use it. It is known as the "INTERCAL System Library."
  930.  
  931. 6.1 Description
  932.  
  933. The program listing begins on the second page following. It is in the same
  934. format as would be produced by the Princeton INTERCAL compiler in FORMAT
  935. mode with WDITH=62 (see section 8). For a descriptioon of the functions
  936. performed by the Library, see section 5.2.
  937.  
  938. 6.2 Analysis
  939.  
  940. We shall not attempe to discuss here the algorithms used, but rather we shall
  941. point out some of the general techniques applicable to a wide range of prob-
  942. lems.
  943.  
  944. Statements 10, 14, 15, and 26 make up a virtual "computed GO TO". When state-
  945. ment 10 is executed, control passes eventually to statement 16 or 11, de-
  946. pending on whether .5 contains #1 or #2, respectively. The value of .5 is
  947. determined in statement 9. which demonstrates another handy technique. To
  948. turn an expression, exp, with value #0 or #1, into #1 or #1 (for use in a 
  949. "GO TO"), use "V'exp'c#1"~#3. To reverse the condition (i.e., convert
  950. #0 to #2 and leave #1 alone) use "V'exp'c#2"~#3.
  951.  
  952. Certain conditions are easily checked. For example, to test for zero, select
  953. the value from itself and select the bottom bit (see statement 54). To test
  954. for all bits being 1's, select the value from itself and select the top bit
  955. (see statement 261). The test to greater than, performed in statements 192
  956. and 193 on 32-bit values, employs binary logical operations, which are per-
  957. formed as follows:
  958.  
  959.     'V.1c.2'~'#0c#65535'
  960.  
  961. for 16-bit values or, for 32-bit values:
  962.  
  963.     "'V":1~'#65535c30'"c":2~'#65535c#0'"'~'#0
  964.     c#65535'"c"'V":1~'#0c#65535'"c":2~'#0
  965.     c#65535'"'~'#0c#65535'"
  966.  
  967. (The proofs are left as an exercise to the reader.)
  968.  
  969. Testing for greater-than with 16-bit values is somewhat simpler and is done
  970. with the pair of statements:
  971.  
  972.     DO .C <- 'V.Ac.B'~'#0c#65535'
  973.     DO .C <- '&"'.A~.C'~'"V'V.C~.C'c#32768"
  974.         ~"#0c#65535"'"c".C~.CZ''ZZZ`#1
  975.  
  976. This sets .C (a dummy variable) to #1 if .A > .B, and #0 otherwiswe. The
  977. expression may be expanded as described above to instead set .C to #1 or
  978. #2.
  979.  
  980. Note also in statement 220 the occurance of ~"#65535c65535". Although
  981. these operations select the entire value, they are not extraneous, as they
  982. ensure that the forthcoming Vs will be operating on 32-bit values.
  983.  
  984. In several vitual computed GO TOs the DO FORGET #1 (statement 15 in the earlier
  985. example) has been omitted, since the next transfer of control would be a 
  986. DO RESUME #1. By making this a DO RESUME #2 instead, the FORGET may be forgotten.
  987.  
  988. In statement 64, note that .2 is STASHed twice by a single statement. This
  989. is perfectly legal.
  990.  
  991. Lastly, note in statements 243 and 214 respectively, expressions for shifting
  992. 16- and 32-bit variables logically one place to the left. Statement 231 dem-
  993. onstrates right-shifting for 32-bit variables.
  994.  
  995. MIKE GETS TO INSERT THE PROGRAM HERE!
  996.  
  997. 6.3 Program Listing
  998.  
  999.     1    (1000)    PLEASE IGNORE .4
  1000.     2        PLEASE ABSTAIN FROM (1005)
  1001.     3    (1009)    DO STASH .1 + .2 + .5 + .6
  1002.     4        DO .4 <- #1
  1003.     5        DO (1004) NEXT
  1004.     6    (1004)    PLEASE FORGET #1
  1005.     7        DO .3 <- 'V.1c.2'~'#0c#65535'
  1006.     8        DO .6 <- '&.1c.2'~'#0c#65535'
  1007.     9        PLEASE DO .5 <- "V!6~#32768'c#1"~#3
  1008.    10        DO (1002) NEXT
  1009.    11        DO .4 <- #2
  1010.    12    (1005)    DO (1006) NEXT
  1011. *  13    (1999)    DOUBLE OR SINGLE PRECISION OVERFLOW
  1012.    14    (1002)    DO (1001) NEXT
  1013.    15    (1006)    PLEASE FORGET #1
  1014.    16        DO .5 <- 'V"!6~.6'~#1"c#1'~#3
  1015.    17        DO (1003) NEXT
  1016.    18        DO .1 <- .3
  1017.    19        DO .2 <- !6c#0'~'#32767c#1'
  1018.    20        DO (1004) NEXT
  1019.    21    (1003)    DO (1001) NEXT
  1020.    22        DO REINSTATE (1005)
  1021.    23    (1007)    PLEASE RETRIEVE .1 + .2 + .5 + .6
  1022.    24        DO REMEMBER .4
  1023.    25        PLEASE RESUME #2
  1024.    26    (1001)    DO RESUME .5
  1025.    27    (1010)    DO STASH .1 + .2 + .4
  1026.    28        DO .4 <- .1
  1027.    29        DO .1 <- 'V.2c#65535'~'#0c#65535'
  1028.    30        DO (1020) NEXT
  1029.    31        PLEASE DO .2 <- .4
  1030.    32        PLEASE DO (1009) NEXT
  1031.    33        DO RETRIEVE .1 + .2 + .4
  1032.    34        PLEASE RESUME #1
  1033.    35    (1020)    DO STASH .2 + .3
  1034.    36        DO .2 <- #1
  1035.    37        PLEASE DO (1021) NEXT
  1036.    38    (1021)    DO FORGET #1
  1037.    39        DO .3 <- "V!1~.2'c#1"~#3
  1038.    40        PLEASE DO .1 <- 'V.1c.2'~'#0c#65535'
  1039.    41        DO (1022) NEXT
  1040.    42        DO .2 <- !2c#0'~'#32767c#1'
  1041.    43        DO (1021) NEXT
  1042.    44    (1023)    PLEASE RESUME .3
  1043.    45    (1022)    DO (1023) NEXT
  1044.    46        PLEASE RETRIEVE .2 + .3
  1045.    47        PLEASE RESUME #2
  1046.    48    (1030)    DO ABSTAIN FROM (1033)
  1047.    49        PLEASE ABSTAIN FROM (1032)
  1048.    50    (1039)    DO STASH :1 + .5
  1049.    51        DO (1530) NEXT
  1050.    52        DO .3 <- :1~#65535
  1051.    53        PLEASE DO .5 <- :1~'#65280c#65280'
  1052.    54        DO .5 <- 'V"!5~.5'~#1"c#1'~#3
  1053.    55        DO (1031) NEXT
  1054.    56    (1032)    DO (1033) NEXT
  1055.    57        DO (1999) NEXT
  1056.    58    (1031)    DO (1001) NEXT
  1057.    59    (1033)    DO .4 <- .5
  1058.    60        DO REINSTATE (1032)
  1059.    61        PLEASE REINSTATE (1033)
  1060.    62        DO RETRIEVE :1 + .5
  1061.    63        PLEASE RESUME #2
  1062.    64    (1040)    PLEASE STASH .1 + .2 + .2 + :1 + :2 + :3
  1063.    65        DO .2 <- #0
  1064.    66        DO (1520) NEXT
  1065.    67        DO STASH :1
  1066.    68        PLEASE RETRIEVE .2
  1067.    69        DO .1 <- .2
  1068.    70        DO .2 <- #0
  1069.    71        PLEASE DO (1520) NEXT
  1070.    72        DO :2 <- :1
  1071.    73        DO RETRIEVE .1 + .2 + :1
  1072.    74        DO (1550) NEXT
  1073.    75        PLEASE DO .3 <- :3
  1074.    76        DO RETRIEVE :1 + :2 + :3
  1075.    77        DO RESUME #1
  1076.    78    (1050)    PLEASE STASH :2 + :3 + .5
  1077.    79        DO :2 <- .1
  1078.    80        PLEASE DO (1550) NEXT
  1079.    81        DO .5 <- :3~'#65280c#65280'
  1080.    82        DO .5 <- 'V"!5~.5'~#1"c#1'~#3
  1081.    83        DO (1051) NEXT
  1082.    84        DO (1999) NEXT
  1083.    85    (1051)    DO (1001) NEXT
  1084.    86        DO .2 <- :3
  1085.    87        PLEASE RETRIEVE :2 + :3 + .5
  1086.    88        DO RESUME #2
  1087.    89    (1500)    PLEASE ABSTAIN FROM (1502)
  1088.    90        PLEASE ABSTAIN FROM (1506)
  1089.    91    (1509)    PLEASE STASH :1 + .1 + .2 + .3 + .4 + .5 + .6
  1090.    92        DO .1 <- :1~#65535
  1091.    93        PLEASE DO .2 <- :2~#65535
  1092.    94        DO (1009) NEXT
  1093.    95        DO .5 <- .3
  1094.    96        PLEASE DO .6 <- .4
  1095.    97        DO .1 <- :1~'#65280c#65280'
  1096.    98        DO .2 <- :2~'#65280c#65280'
  1097.    99        DO (1009) NEXT
  1098.   100        DO .1 <- .3
  1099.   101        PLEASE DO (1503) NEXT
  1100.   102        DO .6 <- .4
  1101.   103        DO .2 <- #1
  1102.   104        DO (1009) NEXT
  1103.   105        DO .1 <- .3
  1104.   106        DO (1501) NEXT
  1105.   107    (1504)    PLEASE RESUME .6
  1106.   108    (1503)    DO (1504) NEXT
  1107.   109    (1501)    DO .2 <- .5
  1108.   110        DO .5 <- 'V"'&.6c.4'~#1"c#2'~#3
  1109.   111        DO (1505) NEXT
  1110.   112    (1506)    DO (1502) NEXT
  1111.   113        PLEASE DO (1999) NEXT
  1112.   114    (1505)    DO (1001) NEXT
  1113.   115    (1502)    DO :4 <- .5
  1114.   116        DO (1520) NEXT
  1115.   117        DO :3 <- :1
  1116.   118        PLEASE RETRIEVE :1 + .1 + .2 + .3 + .4 + .5
  1117.         .6
  1118.   119        DO REINSTATE (1502)
  1119.   120        DO REINSTATE (1506)
  1120.   121        PLEASE RESUME #3
  1121.   122    (1510)    DO STASH :1 + :2 + :4
  1122.   123        DO :1 <- "'V/":2~'#65535c#0'"c#65535'~'#0c#6553
  1123.         5'"c"'V":2~'#0c#65535'"c#65535'~'#0c65535
  1124.         '"
  1125.   124        DO :2 <- #1
  1126.   125        DO (1509) NEXT
  1127.   126        PLEASE RETRIEVE :1
  1128.   127        DO :2 <- :3
  1129.   128        PLEASE DO (1509) NEXT
  1130.   129        DO RETRIEVE :2 + :4
  1131.   130        PLEASE RESUME #1
  1132.   131    (1520)    PLEASE STASH .3 + .4
  1133.   132        DO .3 <- .1~#43690
  1134.   133        DO (1525) NEXT
  1135.   134        PLEASE DO .4 <- 'V.3c".2~#43690"'~'#0c#65535'
  1136.   135        DO .3 <- .1~#21845
  1137.   136        PLEASE DO (1525) NEXT
  1138.   137        DO :1 <- .4c"'V.3c".2~#21845"'~'#0c#65535'"
  1139.   138        PLEASE RETRIEVE .3 + .4
  1140.   139        DO RESUME #1
  1141.   140    (1525)    DO .3 <- '"'"'"!3c#0'~'#32767c#1'"c#0'~'#32767
  1142.         c#1'"c#0'~'#16383c#3'"c#0'~'#4095c#15'
  1143.   141        PLEASE RESUME #1
  1144.   142    (1530)    DO STASH :2 + :3 + .3 + .5
  1145.   143        DO :1 <- #0
  1146.   144        DO :2 <- .2
  1147.   145        DO .3 <- #1
  1148.   146        DO (1535) NEXT
  1149.   147    (1535)    PLEASE FORGET #1
  1150.   148        DO .5 <- "V!1~.3'c#1"~#3
  1151.   149        DO (1531) NEXT
  1152.   150        DO (1500) NEXT
  1153.   151        DO :1 <- :3
  1154.   152        PLEASE DO (1533) NEXT
  1155.   153    (1531)    PLEASE DO (1001) NEXT
  1156.   154    (1533)    DO FORGET #1
  1157.   155        DO .3 <- !3c#0'~'#32767c#1'
  1158.   156        DO :2 <- ":2~'#0c#65535'"c"'":2~'#32767c#0'"c#
  1159.         0'~'#32767c#1'"
  1160.   157        PLEASE DO .5 <- "V!3~.3'c#1"~#3
  1161.   158        DO (1532) NEXT
  1162.   159        DO (1535) NEXT
  1163.   160    (1532)    DO (1001) NEXT
  1164.   161        PLEASE RETRIEVE :2 + :3 + .3 + .5
  1165.   162        DO RESUME #2
  1166.   163    (1540)    PLEASE ABSTAIN FROM (1541)
  1167.   164        DO ABSTAIN FROM (1542)
  1168.   165    (1549)    PLEASE STASH :1 + :2 + :4 + :5 + .1 + .2 + .5
  1169.   166        DO .1 <- :1~#65535
  1170.   167        PLEASE DO .2 <- :2~'#65280c#65280'
  1171.   168        DO .5 <- :1~'#65280c#65280'
  1172.   169        DO (1530) NEXT
  1173.   170        DO :3 <- :1
  1174.   171        DO .2 <- :2~#65535
  1175.   172        PLEASE DO (1530) NEXT
  1176.   173        DO :5 <- :1
  1177.   174        DO .1 <- .5
  1178.   175        DO (1530) NEXT
  1179.   176        DO :4 <- :1
  1180.   177        PLEASE DO :1 <- ":3~'#65280c#65280'"c":5~'652
  1181.         80c#65280'"
  1182.   178        DO .5 <- ':1~:1'~#1
  1183.   179        DO .2 <- :2~'#65280c#65280'
  1184.   180        DO (1530) NEXT
  1185.   181        PLEASE DO .5 <- '"':1~:1'~#1"c.5'~#3
  1186.   182        DO .1 <- :3~#65535
  1187.   183        DO .2 <- #0
  1188.   184        DO (1520) NEXT
  1189.   185        PLEASE DO :2 <- :1
  1190.   186        PLEASE DO .1 <- :4~#65535
  1191.   187        DO (1520) NEXT
  1192.   188        DO (1509) NEXT
  1193.   189        DO .5 <- !5c":4~#3"'~#15
  1194.   190        DO :1 <- :3
  1195.   191        DO :2 <- :5
  1196.   192        DO (1509) NEXT
  1197.   193        PLEASE DO .5 <- !5c"4~#3"'~#63
  1198.   194        DO .5 <- 'V"!5~.5'~#1"c#1'~#3
  1199.   195        PLEASE RETRIEVE :4
  1200.   196    (1541)    DO :4 <- .5
  1201.   197        DO (1543) NEXT
  1202.   198    (1542)    DO (1544) NEXT
  1203.   199        PLEASE DO (1999) NEXT
  1204.   200    (1543)    DO (1001) NEXT
  1205.   201    (1544)    DO REINSTATE (1541)
  1206.   202        PLEASE REINSTATE (1542)
  1207.   203        PLEASE RETRIEVE :1 + :2 + :5 + .1 + .2 + .5
  1208.   204        DO RESUME #2
  1209.   205    (1550)    DO STASH :1 + :4 + :5 + .5
  1210.   206        DO :3 <- #0
  1211.   207        DO .5 <- 'V"':2~:2'~#1"c#1'~#3
  1212.   208        PLEASE DO (1551) NEXT
  1213.  
  1214.  
  1215.  
  1216.  
  1217.  
  1218.  
  1219. 4.6 Programming Suggestions
  1220.  
  1221. For the novice INTERCAL programmer, we provide here a list of suggested 
  1222. INTERCAL programming projects:
  1223.  
  1224. Write an integer exponentiation subroutine.  :1 <- .1 raised to the .2 power.
  1225.  
  1226. Write a double-precision sorting subroutine. Given 32-bit array ;1 of size
  1227. :1. sort the contents into numerically increasing order, leaving the results
  1228. in ;1.
  1229.  
  1230. Generate a table of prime numbers.
  1231.  
  1232. Put together. a floating-point library, using 32-bit variables to represent
  1233. floating-point numbers (let the upper half be the mantissa and the lower
  1234. half be the characteristic). The library should be capable of performing 
  1235. floating-point addition, subtraction, multiplication, and division, as well
  1236. as the natural logarithm function.
  1237.  
  1238. Program a Fast Fourier Transform (FFT). This project would probably entail
  1239. the writing of the floating-point library as well as sine ans cosine functions.
  1240.  
  1241. Calculate, to :1 places, the value of pi.
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249. 7. ERROR MESSAGES
  1250.  
  1251. Due to INTERCAL's implementation of comment lines (see section 4.5), most
  1252. error messages are produced during execution instead of during compilation.
  1253. All errors except those not causing immediate termination of program execution
  1254. are treated as fatal.
  1255.  
  1256. 7.1 Format
  1257.  
  1258. All error messages appear in the following form:
  1259.  
  1260.     ICLnnnI (error message)
  1261.         ON THE WAY TO STATEMENT nnnn
  1262.         CORRECT SOURSE AND RESUBMIT
  1263.  
  1264. The message varies depending upon the error involved. For undecodable state-
  1265. ments the message is the statement itself. The second line tells which state-
  1266. ment would have been executed next had the error not occurred. Note that if
  1267. the error is due to 80 attempted levels of NEXTing, the statement which would
  1268. have been executed next need not be anywhere near the statement causing the
  1269.  error.
  1270.  
  1271. 7.2 Messages
  1272.  
  1273. Brief descriptions of the different error types are listed below according
  1274. to message number.
  1275.  
  1276.     000 An undecodable statement has been encountered in the course of exe-
  1277.     cution. Note that keypunching errors can be slightly disastrous,
  1278.     since if 'FORGET' were misspelled F-O-R-G-E-R, the results would 
  1279.     probably not be those desired. Extreme misspellings may have even 
  1280.     more surprising conequences. For example, misspelling 'FORGET' 
  1281.     R-E-S-U-M-E could have drastic results.
  1282.  
  1283.     017 An expression contains a syntax error.
  1284.  
  1285.     079 Improper use has been made of statement identifiers.
  1286.  
  1287.     099 Improper use has been made of statement identifiers.
  1288.  
  1289.     123 Program has attempted 80 levels of NEXTing.
  1290.  
  1291.     129 Program has attempted to transfer to a non-existent line label.
  1292.  
  1293.     139 An ABSTAIN or REINSTATE statement referances a non-existent line label.
  1294.  
  1295.     182 A line label has been multiply defined.
  1296.  
  1297.     197 An invalid line label has been encountered.
  1298.  
  1299.     200 An expression involves an unidentified variable.
  1300.  
  1301.     240 An attempt has been made to give an array a dimension of zero.
  1302.  
  1303.     241 Invalid dimensioning information was supplied in defining or using
  1304.     an array.
  1305.  
  1306.     275 A 32-bit value has been assigned to a 16-bit variable.
  1307.  
  1308.     436 A retrieval has been attempted for an unSTASHed value.
  1309.  
  1310.     533 A WRITE IN statement or interleave (c) operation has produced 
  1311.     value requiring over 32 bits to represent.
  1312.  
  1313.     562 Insufficient data.
  1314.  
  1315.     579 Input data is invalid.
  1316.  
  1317.     621 The expression of a RESUME statement evaluated to #0.
  1318.  
  1319.     632 Program execution was terminated via a RESUME statement instead of
  1320.     GIVE UP.
  1321.  
  1322.     633 Execution has passed beyond the last statment of the program.
  1323.  
  1324.     774 A compiler error has occurred (see section 8.1).
  1325.  
  1326.     778 An unexplainable compiler error has occurred (see J. Lyon or B. Woods).
  1327.  
  1328.  
  1329.  
  1330.  
  1331.  
  1332.  
  1333.                 [3]
  1334.             TONSIL A
  1335.  
  1336.  
  1337.  
  1338. The Official INTERCAL Character Set
  1339.  
  1340. Tabulated on page XX are all the characters used in INTERCAL, excepting
  1341. letters and digits, along with their names and interpretations. Also included
  1342. are several characters not used in INTERCAL, which are presented for complete-
  1343. ness and to allow for future expansion.
  1344.  
  1345.  
  1346.  
  1347.  
  1348.  
  1349.  
  1350.  
  1351.  
  1352.  
  1353.  
  1354.  
  1355.  
  1356.  
  1357.  
  1358.  
  1359.  
  1360.  
  1361.  
  1362.  
  1363.  
  1364.  
  1365.  
  1366.  
  1367.  
  1368.  
  1369.  
  1370.  
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380.  
  1381.  
  1382.  
  1383. _____________________
  1384. 3) Since all other reference manuals have Appendices, it was decided that
  1385. the INTERCAL manual should contain some other type of removable organ.
  1386.  
  1387. 4) This footnote intentionally unreferenced.
  1388.  
  1389.  
  1390.  
  1391.  
  1392.  
  1393.  
  1394. _______________________________________________________________________
  1395. |                                                                     |
  1396. |Character    Name            Use (if any)                  |
  1397. |                                                                     |
  1398. |    .        spot            identify 16-bit variable      |
  1399. |    :         two-spot        identify 32-bit variable      |
  1400. |    ,        tail            identify 16-bit array         |
  1401. |    ;        hybrid            identify 32-bit array         |
  1402. |    #        mesh            identify constant             |
  1403. |    =        half-mesh                          |
  1404. |    '        spark            grouper                             |
  1405. |    `        backspark                          |
  1406. |    !        wow            equivalent to spark-spot      |
  1407. |    ?         what                                                  |
  1408. |    "        rabbit-ears        grouper                       |
  1409. |    !`        rabbit            equivalent to ears-spot       |
  1410. |    |        spike                                                 |
  1411. |    %      double-oh-seven        percentage qualifier          |
  1412. |    -        worm            used with angles          |
  1413. |    <        angle            used with worms              |
  1414. |    >        right angle                          |
  1415. |    (        wax            precedes line label           |
  1416. |    )        wane            follows line label          |
  1417. |    [        U turn                              |
  1418. |    ]        U turn back                          |
  1419. |    {        embrace                               |
  1420. |    }        bracelet                          |
  1421. |    *        splat            flags invalid statements      |
  1422. |    &        ampersand[5]        unary logical AND          |
  1423. |    V        V            unary logical OR          |
  1424. |            (or book)                          |
  1425. |    V        bookworm        unary exclusive OR          |
  1426. |        (or universal qualifier)                  |
  1427. |    $        big money                          |
  1428. |    c        change            binary mingle              |
  1429. |    ~        sqiggle            binary select              |
  1430. |    _        flat worm                          |
  1431. |            overline        indicates "times 1000"          |
  1432. |    +        intersection        separates list items          |
  1433. |    /        slat                              |
  1434. |    \        backslat                          |
  1435. |    @        whirlpool                          |
  1436. |    -'        hookworm                          |
  1437. |    ^        shark                              |
  1438. |            (or simply sharkfin)                      |
  1439. |    #I[]        blotch                              |
  1440. |_____________________________________________________________________|
  1441.  
  1442.  
  1443.         Table 2 (top view). INTERCAL character set.
  1444.  
  1445. __________________________________
  1446.  
  1447. 5) Got any better ideas?
  1448.  
  1449.  
  1450. NOTES ON THE ATARI IMPLEMENTATION
  1451.  
  1452. The Atari implementation of INTERCAL differs from the
  1453. original Princeton version primarily in the use of ASCII rather
  1454. than EBCDIC. Since there is no "change" sign (c) in ASCII, we have
  1455. substituted the "big money" ($) as the mingle operator. We feel
  1456. that this correctly represents the increasing cost of software
  1457. in relation to hardware. (Consider that in 1970 one could get
  1458. RUNOFF for free, to run on a $20K machine, whereas today a not
  1459. quite as powerful formatter costs $99 and runs on a $75 machine.) 
  1460. We also feel that there should be no defensible contention that
  1461. INTERCAL has any sense. Also, since overpunches are difficult to
  1462. read on the average VDT, the exclusive-or operator may be written
  1463. ?. This correctly expresses the average person's reaction on first
  1464. encountering exclusive-or, especially on a PDP-11. Note that in
  1465. both of these cases, the over-punched symbol may also be used if
  1466. one is masochistic, or concerned with portability to the Princeton
  1467. compiler. The correct over-punch for "change" is "c<backspace>/"
  1468. and the correct over-punch for V is "V<backspace>-". These
  1469. codes will be properly printed if you have a proper printer, and the
  1470. corresponding EBCDIC code will be produced by the /IBM option on the
  1471. LIST command.
  1472.  
  1473.  cheers, Mike
  1474. -- 
  1475. Ken Johnson, AI Applications Institute, 80 South Bridge, Edinburgh EH1 1HN
  1476. E-mail ken@aiai.ed.ac.uk, phone 031-225 4464 extension 212
  1477. `I have read your article, Mr Johnson, and I am no wiser now than when I
  1478. started'.  -- `Possibly not, sir, but far better informed.'
  1479.